#!/usr/bin/env python
# encoding: utf-8
# @author: Lin Han
# @contact: voldemort22@126.com
# @file: update_03_20210507.py
# @time: 2021/5/7 11:12
# @desc:
import pymongo

from .utils.mongo_tools import retrieve_all_mongo_values, update_mongo_value
from .utils.oss.oss import download_file_from_oss
from .utils.utils import read_json
from .views.configs import MONGO_DATABASE_NAME, STANDARD_CLAMP_COLLECTION

standard_clamps = retrieve_all_mongo_values({}, database_name=MONGO_DATABASE_NAME, collection_name=STANDARD_CLAMP_COLLECTION)

for i in standard_clamps:
    download_file_from_oss(i["file"]["jsonAliOssAddress"])
    i["data"] = read_json(i["file"]["jsonAliOssAddress"])
    update_mongo_value(
        filter_condition={"number": i["number"]},
        new_value={"$set": i},
        database_name=MONGO_DATABASE_NAME,
        collection_name=STANDARD_CLAMP_COLLECTION,
    )
